package com.drojian.singleton.type3;

import org.junit.Test;

/**
 * 懒汉式（线程不安全）
 */
public class SingletonTest03 {
    @Test
    public void test01(){
        Singleton instance = Singleton.getInstance();
        Singleton instance2 = Singleton.getInstance();
        System.out.println(instance == instance2);
    }}

class Singleton{
    private  static Singleton instance;

    public Singleton() {
    }
    public static Singleton getInstance() {
        if(instance == null){
            instance =  new Singleton();
        }
        return instance;
    }
}